package com.quad.innovators.salesease.enums;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.quad.innovators.salesease.exception.BusinessException;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;

/**
 * @author : shanshan.li
 * @createTime : 2025/3/28 14:53
 * @Version : 1.0 
 */
@Getter
public enum BackstageStatusEnum {
    IN_WAREHOUSE(1, "在仓库"),
    IN_SHOP(2, "在门店"),
    SOLD(3, "已销售"),
    USED(4, "推广已使用"),
    TRANSFER(5, "已调拨");

    private final int code;
    private final String description;

    BackstageStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    static final Map<Integer, BackstageStatusEnum> map = new HashMap<>();

    static {
        BackstageStatusEnum[] values = values();
        for (BackstageStatusEnum value : values) {
            map.put(value.code, value);
        }
    }

    public static BackstageStatusEnum useCodeGetEnum(Integer code) {
        BackstageStatusEnum arrivalStatusEnum = map.getOrDefault(code, null);
        if (ObjectUtils.isNull(arrivalStatusEnum)) {
            throw BusinessException.resultCode(ResultCode.NOT_FOUND);
        }
        return arrivalStatusEnum;
    }
}
